home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qtextstream.h.z / qtextstream.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  6.7 KB  |  231 lines

  1. /****************************************************************************
  2. ** $Id: qtextstream.h,v 2.8 1998/07/03 00:09:47 hanord Exp $
  3. **
  4. ** Definition of QTextStream class
  5. **
  6. ** Created : 940922
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QTEXTSTREAM_H
  25. #define QTEXTSTREAM_H
  26.  
  27. #ifndef QT_H
  28. #include "qiodevice.h"
  29. #include "qstring.h"
  30. #include <stdio.h>
  31. #endif // QT_H
  32.  
  33.  
  34. class QTextStream                // text stream class
  35. {
  36. public:
  37.     QTextStream();
  38.     QTextStream( QIODevice * );
  39.     QTextStream( QByteArray, int mode );
  40.     QTextStream( FILE *, int mode );
  41.     virtual ~QTextStream();
  42.  
  43.     QIODevice    *device() const;
  44.     void     setDevice( QIODevice * );
  45.     void     unsetDevice();
  46.  
  47.     bool     eof() const;
  48.  
  49.     QTextStream &operator>>( char & );
  50.     QTextStream &operator>>( signed short & );
  51.     QTextStream &operator>>( unsigned short & );
  52.     QTextStream &operator>>( signed int & );
  53.     QTextStream &operator>>( unsigned int & );
  54.     QTextStream &operator>>( signed long & );
  55.     QTextStream &operator>>( unsigned long & );
  56.     QTextStream &operator>>( float & );
  57.     QTextStream &operator>>( double & );
  58.     QTextStream &operator>>( char * );
  59.     QTextStream &operator>>( QString & );
  60.  
  61.     QTextStream &operator<<( char );
  62.     QTextStream &operator<<( signed short );
  63.     QTextStream &operator<<( unsigned short );
  64.     QTextStream &operator<<( signed int );
  65.     QTextStream &operator<<( unsigned int );
  66.     QTextStream &operator<<( signed long );
  67.     QTextStream &operator<<( unsigned long );
  68.     QTextStream &operator<<( float );
  69.     QTextStream &operator<<( double );
  70.     QTextStream &operator<<( const char * );
  71.     QTextStream &operator<<( void * );        // any pointer
  72.  
  73.     QTextStream &readRawBytes( char *, uint len );
  74.     QTextStream &writeRawBytes( const char *, uint len );
  75.  
  76.     QString    readLine();
  77.  
  78.     enum {
  79.     skipws      = 0x0001,            // skip whitespace on input
  80.     left      = 0x0002,            // left-adjust output
  81.     right      = 0x0004,            // right-adjust output
  82.     internal  = 0x0008,            // pad after sign
  83.     bin      = 0x0010,            // binary format integer
  84.     oct      = 0x0020,            // octal format integer
  85.     dec      = 0x0040,            // decimal format integer
  86.     hex      = 0x0080,            // hex format integer
  87.     showbase  = 0x0100,            // show base indicator
  88.     showpoint = 0x0200,            // force decimal point (float)
  89.     uppercase = 0x0400,            // upper-case hex output
  90.     showpos      = 0x0800,            // add '+' to positive integers
  91.     scientific= 0x1000,            // scientific float output
  92.     fixed      = 0x2000            // fixed float output
  93.     };
  94.  
  95.     static const int basefield;            // bin | oct | dec | hex
  96.     static const int adjustfield;        // left | right | internal
  97.     static const int floatfield;        // scientific | fixed
  98.  
  99.     int      flags() const;
  100.     int      flags( int f );
  101.     int      setf( int bits );
  102.     int      setf( int bits, int mask );
  103.     int      unsetf( int bits );
  104.  
  105.     void  reset();
  106.  
  107.     int      width()    const;
  108.     int      width( int );
  109.     int      fill()    const;
  110.     int      fill( int );
  111.     int      precision()    const;
  112.     int      precision( int );
  113.  
  114. private:
  115.     long     input_int();
  116.     QTextStream &output_int( int, ulong, bool );
  117.     QIODevice    *dev;
  118.     int         fflags;
  119.     int         fwidth;
  120.     int         fillchar;
  121.     int         fprec;
  122.     bool     fstrm;
  123.     bool     owndev;
  124.  
  125. private:    // Disabled copy constructor and operator=
  126.     QTextStream( const QTextStream & );
  127.     QTextStream &operator=( const QTextStream & );
  128. };
  129.  
  130. typedef QTextStream QTS;
  131.  
  132.  
  133. /*****************************************************************************
  134.   QTextStream inline functions
  135.  *****************************************************************************/
  136.  
  137. inline QIODevice *QTextStream::device() const
  138. { return dev; }
  139.  
  140. inline bool QTextStream::eof() const
  141. { return dev ? dev->atEnd() : FALSE; }
  142.  
  143. inline int QTextStream::flags() const
  144. { return fflags; }
  145.  
  146. inline int QTextStream::flags( int f )
  147. { int oldf = fflags;  fflags = f;  return oldf; }
  148.  
  149. inline int QTextStream::setf( int bits )
  150. { int oldf = fflags;  fflags |= bits;  return oldf; }
  151.  
  152. inline int QTextStream::setf( int bits, int mask )
  153. { int oldf = fflags;  fflags = (fflags & ~mask) | (bits & mask); return oldf; }
  154.  
  155. inline int QTextStream::unsetf( int bits )
  156. { int oldf = fflags;  fflags &= ~bits;    return oldf; }
  157.  
  158. inline int QTextStream::width() const
  159. { return fwidth; }
  160.  
  161. inline int QTextStream::width( int w )
  162. { int oldw = fwidth;  fwidth = w;  return oldw;     }
  163.  
  164. inline int QTextStream::fill() const
  165. { return fillchar; }
  166.  
  167. inline int QTextStream::fill( int f )
  168. { int oldc = fillchar;    fillchar = f;  return oldc;  }
  169.  
  170. inline int QTextStream::precision() const
  171. { return fprec; }
  172.  
  173. inline int QTextStream::precision( int p )
  174. { int oldp = fprec;  fprec = p;     return oldp;  }
  175.  
  176.  
  177. /*****************************************************************************
  178.   QTextStream manipulators
  179.  *****************************************************************************/
  180.  
  181. typedef QTextStream & (*QTSFUNC)(QTextStream &);// manipulator function
  182. typedef int (QTextStream::*QTSMFI)(int);    // manipulator w/int argument
  183.  
  184. class QTSManip {                // text stream manipulator
  185. public:
  186.     QTSManip( QTSMFI m, int a ) { mf=m; arg=a; }
  187.     void exec( QTextStream &s ) { (s.*mf)(arg); }
  188. private:
  189.     QTSMFI mf;                    // QTextStream member function
  190.     int       arg;                    // member function argument
  191. };
  192.  
  193. inline QTextStream &operator>>( QTextStream &s, QTSFUNC f )
  194. { return (*f)( s ); }
  195.  
  196. inline QTextStream &operator<<( QTextStream &s, QTSFUNC f )
  197. { return (*f)( s ); }
  198.  
  199. inline QTextStream &operator<<( QTextStream &s, QTSManip m )
  200. { m.exec(s); return s; }
  201.  
  202. QTextStream &bin( QTextStream &s );        // set bin notation
  203. QTextStream &oct( QTextStream &s );        // set oct notation
  204. QTextStream &dec( QTextStream &s );        // set dec notation
  205. QTextStream &hex( QTextStream &s );        // set hex notation
  206. QTextStream &endl( QTextStream &s );        // insert EOL ('\n')
  207. QTextStream &flush( QTextStream &s );        // flush output
  208. QTextStream &ws( QTextStream &s );        // eat whitespace on input
  209. QTextStream &reset( QTextStream &s );        // set default flags
  210.  
  211. inline QTSManip setw( int w )
  212. {
  213.     QTSMFI func = &QTextStream::width;
  214.     return QTSManip(func,w);
  215. }
  216.  
  217. inline QTSManip setfill( int f )
  218. {
  219.     QTSMFI func = &QTextStream::fill;
  220.     return QTSManip(func,f);
  221. }
  222.  
  223. inline QTSManip setprecision( int p )
  224. {
  225.     QTSMFI func = &QTextStream::precision;
  226.     return QTSManip(func,p);
  227. }
  228.  
  229.  
  230. #endif // QTEXTSTREAM_H
  231.